<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="80%"
    :before-close="handleClose"
    append-to-body
  >
    <div class="tit">选择了 {{ multipleSelection.length }} 个料单,共 {{ totalWeight }} t</div>
    <el-table v-loading="loading" ref="multipleTable" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="序号" width="55" align="center">
        <template slot-scope="scope">{{ scope.$index + 1 }}</template>
      </el-table-column>
      <el-table-column prop="name" label="料单编号" align="center"></el-table-column>
      <el-table-column prop="date" label="计划到场时间" align="center"></el-table-column>
      <el-table-column prop="name" label="工区" align="center"></el-table-column>
      <el-table-column prop="name" label="料单名称" align="center"></el-table-column>
      <el-table-column prop="weight" label="总重量(t)" align="center"></el-table-column>
      <el-table-column prop="date" label="提交日期" align="center"></el-table-column>
      <el-table-column prop="name" label="备注" align="center"></el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: "",
  components: {},
  props: {},
  data() {
    return {
      dialogVisible: false,
      title: '',
      loading: false,
      tableData: [
        {
          date: "2016-05-03",
          name: "王小虎",
          weight: 1
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          weight: 1
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          weight: 1
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          weight: 1
        },
        {
          date: "2016-05-08",
          name: "王小虎",
          weight: 1
        },
        {
          date: "2016-05-06",
          name: "王小虎",
          weight: 1
        },
        {
          date: "2016-05-07",
          name: "王小虎",
          weight: 1
        },
      ],

      multipleSelection: [],
      totalWeight: 0
    };
  },
  filters: {},
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  beforeDestroy() {},
  methods: {
    add() {
      this.dialogVisible = true;
      this.title = "添加料单";
      this.$nextTick(function() {
        this.multipleSelection = []
        this.$refs.multipleTable.clearSelection();
      })
    },
    submitForm() {
      console.log(this.multipleSelection);
      this.dialogVisible = false;
    },
    handleClose(done) {
      this.$modal
        .confirm("确认关闭？")
        .then((_) => {
          this.dialogVisible = false;
        })
        .catch((_) => {});
    },
    handleSelectionChange(val) {
      this.totalWeight = 0
      this.multipleSelection = val;
      if (val.length) {
        val.forEach(item => {
          this.totalWeight += item.weight
        })
      }
    }
  },
};
</script>

<style scoped lang="scss">
.tit {
  font-weight: 500;
  font-size: 16px;
  color: #101010;
  margin-bottom: 20px;
}
</style>
